<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\PaymentOrder;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class PaymentOrderController extends AdminController
{
    protected $typeList = [0=>'押金订单',1=>'好物商品订单',2=>'虚拟商品订单', 3=>'二手闲置订单'];

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new PaymentOrder(), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->model()->where("pay_status",">",0);
            $grid->column('id')->sortable();
            $grid->column('out_trade_no');
            $grid->column('type')->using($this->typeList)->label();
            $grid->column('user_id');
            $grid->column('shop_id');
            $grid->column('amount');
            $grid->column('pay_status')->using(['待支付','已付款','待退款'])->label(['default','success','danger']);
            $grid->column('pay_at');
            $grid->column('transaction_id');
            $grid->column('refund_id');
            $grid->column('refund_at');
            $grid->column('reason');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new PaymentOrder(), function (Show $show) {
            $show->field('id');
            $show->field('out_trade_no');
            $show->field('type');
            $show->field('user_id');
            $show->field('shop_id');
            $show->field('amount');
            $show->field('pay_status');
            $show->field('pay_at');
            $show->field('transaction_id');
            $show->field('refund_id');
            $show->field('refund_at');
            $show->field('reason');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new PaymentOrder(), function (Form $form) {
            $form->display('id');
            $form->text('out_trade_no');
            $form->text('type');
            $form->text('user_id');
            $form->text('shop_id');
            $form->text('amount');
            $form->text('pay_status');
            $form->text('pay_at');
            $form->text('transaction_id');
            $form->text('refund_id');
            $form->text('refund_at');
            $form->text('reason');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
